package gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;

@SuppressWarnings("serial")
public class PanelEleccion extends PanelImagen {

	/**
	 * Declara publico los botones accesibles desde el control de eventos
	 * central.
	 */
	public JButton btnListo;
	
	private JPanel panel;

	/** Construye el panel que muestra los animales. */
	public PanelEleccion() {

		setPreferredSize(new Dimension(822, 520));
		setLayout(null);
		this.setBackground("img/paneles/panelPergaminoG.png");

		JPanel panelBoton = new JPanel();
		panelBoton.setOpaque(false);
		panelBoton.setBounds(0, 0, 822, 520);
		add(panelBoton);
		panelBoton.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		// Construye boton que finaliza la muestra de animales. 
		btnListo = new JButton("Haga click aquí para continuar");
		btnListo.setForeground(Color.ORANGE);
		btnListo.setIcon(new ImageIcon("img/paneles/fondoBotonElecion.png"));
		panelBoton.add(btnListo);
		btnListo.setHorizontalTextPosition(SwingConstants.CENTER);
		btnListo.setRolloverEnabled(false);
		btnListo.setRequestFocusEnabled(false);
		btnListo.setVerifyInputWhenFocusTarget(false);
		btnListo.setFont(new Font("Dialog", Font.BOLD, 23));
		btnListo.setOpaque(false);
		btnListo.setDefaultCapable(false);
		btnListo.setContentAreaFilled(false);
		btnListo.setBorder(null);
		btnListo.setBorderPainted(false);
		btnListo.setPreferredSize(new Dimension(822, 520));

		JPanel borde = new PanelImagen("img/paneles/panelPergaminoGBorde.png");
		borde.setBounds(0, 0, 822, 520);
		borde.setOpaque(false);
		add(borde);

		panel = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setVgap(12);
		flowLayout.setHgap(10);
		panel.setBounds(18, 20, 794, 488);
		panel.setOpaque(false);
		add(panel);

		String[] animales = { "img/elementos/aguila.jpg",
				"img/elementos/calamar.jpg", "img/elementos/cangrejo.jpg",
				"img/elementos/cisne.jpg", "img/elementos/cocodrilo.jpg",
				"img/elementos/erizodemar.jpg", "img/elementos/caracol.jpg",
				"img/elementos/cebra.jpg", "img/elementos/delfin.jpg",
				"img/elementos/garrapata.jpg", "img/elementos/gallo.jpg",
				"img/elementos/lechuza.jpg", "img/elementos/arana.jpg",
				"img/elementos/ballena.jpg", "img/elementos/leon.jpg",
				"img/elementos/lombriz.jpg", "img/elementos/mariposa.jpg",
				"img/elementos/rana.jpg", "img/elementos/raya.jpg",
				"img/elementos/tortuga.jpg", "img/elementos/tucan.jpg",
				"img/elementos/perro.jpg", "img/elementos/mejillon.jpg",
				"img/elementos/escorpion.jpg", "img/elementos/elefante.jpg",
				"img/elementos/lechuza.jpg", "img/elementos/conejo.jpg",
				"img/elementos/cobra.jpg" };
		
		for(int i=0; i<28; i++)
			crearCuadro(animales[i]);

	}

	/** Coloca cada imagen. */
	private void crearCuadro(String imgPath) {

		PanelImagen panelImg = new PanelImagen(imgPath);
		panelImg.setDoubleBuffered(false);
		panelImg.setEnabled(false);
		panelImg.setFocusTraversalKeysEnabled(false);
		panelImg.setFocusable(false);
		panelImg.setBorder(new LineBorder(new Color(0, 0, 0), 2));
		panelImg.setPreferredSize(new Dimension(100, 100));
		panelImg.setLayout(new BorderLayout(0, 0));
		panel.add(panelImg);
	}

	/** Crea los eventos. */
	public void setActionListener(ControlCentral e) {
		btnListo.addActionListener(e);
	}
}
